package cn.gjxblog.producer;

import cn.gjxblog.Barista;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/7/5 16:44
 */
@EnableBinding(Barista.class)
@Service
@Slf4j
public class RabbitSender {

    @Resource
    private Barista barista;

    //发送消息
    public String sendMessage(Object message,Map properties){
        MessageHeaders messageHeaders = new MessageHeaders(properties);
        Message<Object> msg = MessageBuilder.createMessage(message, messageHeaders);

        boolean sendstatus = barista.logoutput().send(msg);
        log.info("----------sending------------");
        log.info("发送数据："+message,"发送状态："+sendstatus);

        return null;
    }
}
